/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.rest;

import me.zhengjie.annotation.Log;
import lombok.RequiredArgsConstructor;
import java.util.List;

import me.zhengjie.annotation.rest.AnonymousGetMapping;
import me.zhengjie.annotation.rest.AnonymousPostMapping;
import me.zhengjie.modules.poker.PokerFormatUtil;
import me.zhengjie.modules.system.domain.PokerUserActivatInfo;
import me.zhengjie.modules.system.domain.dto.PokerUserActivatInfoQueryCriteria;
import me.zhengjie.modules.system.service.PokerUserActivatInfoService;
import me.zhengjie.utils.SecurityUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.utils.PageResult;

/**
* @author greazy
* @date 2025-04-07
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "/userActInfo")
@RequestMapping("/api/pokerUserActivatInfo")
public class PokerUserActivatInfoController {

    private final PokerUserActivatInfoService pokerUserActivatInfoService;

    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('pokerUserActivatInfo:list')")
    public void exportPokerUserActivatInfo(HttpServletResponse response, PokerUserActivatInfoQueryCriteria criteria) throws IOException {
        pokerUserActivatInfoService.download(pokerUserActivatInfoService.queryAll(criteria), response);
    }

    @GetMapping
    @ApiOperation("查询/userActInfo")
    @PreAuthorize("@el.check('pokerUserActivatInfo:list')")
    public ResponseEntity<PageResult<PokerUserActivatInfo>> queryPokerUserActivatInfo(PokerUserActivatInfoQueryCriteria criteria) {
        Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
        return new ResponseEntity<>(pokerUserActivatInfoService.queryAll(criteria, page), HttpStatus.OK);
    }

    @PostMapping
    @Log("新增/userActInfo")
    @ApiOperation("新增/userActInfo")
    @PreAuthorize("@el.check('pokerUserActivatInfo:add')")
    public ResponseEntity<Object> createPokerUserActivatInfo(@Validated @RequestBody PokerUserActivatInfo resources) {
        pokerUserActivatInfoService.create(resources);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PutMapping
    @Log("修改/userActInfo")
    @ApiOperation("修改/userActInfo")
    @PreAuthorize("@el.check('pokerUserActivatInfo:edit')")
    public ResponseEntity<Object> updatePokerUserActivatInfo(@Validated @RequestBody PokerUserActivatInfo resources) {
        pokerUserActivatInfoService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除/userActInfo")
    @ApiOperation("删除/userActInfo")
    @PreAuthorize("@el.check('pokerUserActivatInfo:del')")
    public ResponseEntity<Object> deletePokerUserActivatInfo(@ApiParam(value = "传ID数组[]") @RequestBody List<Integer> ids) {
        pokerUserActivatInfoService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     *
     * @param taskId
     * @param activateId
     * @param cardNum
     * @param type  1一次换三张 2一次换一张
     * @return
     */
    @AnonymousPostMapping("/c")
    public ResponseEntity<Object> changeCard(String taskId, Integer activateId, Integer cardNum,Integer type) {
        return pokerUserActivatInfoService.changeCard(taskId, activateId, cardNum, type);

    }

    @AnonymousPostMapping("/j")
    public ResponseEntity<Object> joinActive(String taskId, Integer activateId) {
        return pokerUserActivatInfoService.joinActive(taskId, activateId);

    }


    @AnonymousGetMapping("/i")
    public ResponseEntity<Object> activateInfo(String taskId, Integer activateId) {
        return  pokerUserActivatInfoService.activateInfo(taskId,activateId);
    }
    @AnonymousGetMapping("/iKing")
    public ResponseEntity<Object> iKing( Integer activateId) {
        return  pokerUserActivatInfoService.iKing(activateId);
    }

    @AnonymousPostMapping("/doVote")
    public ResponseEntity<Object> doVote( Integer activateId,Integer groupId,Integer bianbianVal) {
        return  pokerUserActivatInfoService.doVote(activateId,groupId,bianbianVal);
    }

    @AnonymousPostMapping("/selectGroup")
    public ResponseEntity<Object> selectGroup( Integer activateId,Integer groupId) {
        return  pokerUserActivatInfoService.selectGroup(activateId,groupId);
    }
}